<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        let a = "全局变量a"

        /* 
            函数在作用域，在函数创建时就已经确定的（词法作用域）
                和调用的位置无关

            闭包利用的就是词法作用域
        
        */
        function fn(){
            console.log(a)
        }


        function fn2(){
            let a = "fn2中的a"

            fn()
        }

        // fn2()


        function fn3(){
            let a = "fn3中的a"

            function fn4(){
                console.log(a)
            }

            return fn4
        }

        let fn4 = fn3()

        fn4()

    </script>
</head>
<body>
    
</body>
</html>